﻿using System;
using System.Linq;
using System.Security.Principal;
using Se.Framework.Common.Data;

namespace Se.Framework.Common.Security
{
    public class UserPrincipal : IPrincipal
    {
        private readonly IUserData principal;
        private readonly IPrincipal nestedPrincipal;

        public UserPrincipal(IUserData principal, IPrincipal nestedPrincipal)
        {
            this.nestedPrincipal = nestedPrincipal;
            this.principal = principal;
        }

        public UserPrincipal(IUserData principal)
            : this(principal, null)
        {
        }

        public bool IsInRole(string role)
        {
            return principal.HasAction(role);
        }

        public IIdentity Identity
        {
            get
            {
                return principal;
            }
        }

        public IPrincipal NestedPrincipal
        {
            get
            {
                return nestedPrincipal;
            }
        }
    }
}
